<template>
  <div>
    <el-table ref="table" v-loading="loading" :data="list" style="width: 100%" border>
      <el-table-column width="50" label="序号" key="1" header-align="center" align="center">
        <template slot-scope="scope">
          <div>{{$parent.params.per_limit*($parent.params.page-1)+scope.$index+1}}</div>
        </template>
      </el-table-column>
      <el-table-column header-align="center" align="center" key="2" prop="id" label="ID" width="60"></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="merchant_no"
        key="3"
        show-overflow-tooltip
        label="商户编号"
        width="140"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="sign_name"
        key="4"
        show-overflow-tooltip
        label="签约名"
        width="100"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        key="5"
        show-overflow-tooltip
        prop="merchant_name"
        label="展示名"
        width="120"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        key="6"
        show-overflow-tooltip
        prop="merchant_type_name"
        label="商户类型"
        width="80"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="lp_name"
        key="7"
        show-overflow-tooltip
        label="法人名字"
        width="110"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        prop="merchant_type_name"
        key="8"
        show-overflow-tooltip
        label="商户类型"
        width="90"
      ></el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        show-overflow-tooltip
        key="9"
        prop="lp_name"
        label="法人"
        width="80"
      ></el-table-column>
      <el-table-column
        header-align="center"
        show-overflow-tooltip
        key="10"
        align="center"
        prop="address_info"
        label="所在地址"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        show-overflow-tooltip
        key="11"
        align="center"
        prop="settle_bank_type_name"
        label="结算类型"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        show-overflow-tooltip
        key="12"
        align="center"
        prop="holder_name"
        label="开户人"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        show-overflow-tooltip
        key="13"
        align="center"
        prop="card_info"
        label="结算卡信息"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        v-if="status ===''||status===5||status===3"
        show-overflow-tooltip
        key="14"
        align="center"
        prop="fail_reason"
        label="失败原因和备注"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        v-if="status===''||status ===1"
        show-overflow-tooltip
        key="15"
        align="center"
        prop="created_at"
        label="创建时间"
        width="145"
      ></el-table-column>
      <el-table-column
        header-align="center"
        v-if="status ===''||status===5||status===3"
        show-overflow-tooltip
        key="16"
        align="center"
        prop="reported_at"
        label="失败时间"
        width="145"
      ></el-table-column>
      <el-table-column
        header-align="center"
        v-if="status===''||status ===2"
        show-overflow-tooltip
        key="17"
        align="center"
        prop="register_at"
        label="进件时间"
        width="125"
      ></el-table-column>
      <el-table-column
        header-align="center"
        v-if="status===''||status ===6"
        show-overflow-tooltip
        key="18"
        align="center"
        prop="finished_at"
        label="完成时间"
        width="125"
      ></el-table-column>
      <el-table-column
        fixed="right"
        key="19"
        label="操作"
        min-width="200"
        header-align="center"
        align="center"
      >
        <template slot-scope="scope">
          <div>
            <el-button
              v-if="scope.row.is_download===1"
              @click="downLoad(scope.row.id)"
              type="text"
              v-loading="downLoading"
            >下载去报备</el-button>
            <el-button v-if="scope.row.is_report===1" @click="toExamine(scope.row)" type="text">去报备</el-button>
            <el-button v-if="scope.row.status===3" @click="rollback(scope.row)" type="text">重新提交初审</el-button>
            <el-button v-if="scope.row.status===0" @click="rollback(scope.row)" type="text">提交进件</el-button>
            <el-button @click="seeDetail(scope.row.id)" type="text">查看详情</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
// import { againApply, rollback, openAgain } from '@/api/report-admin/silver-fill'
import { singleDownLoad, toExamine } from '@/api/report-admin/silver-fill'

// 等待审核
export default {
  props: {
    list: {
      type: Array,
      required: true
    },
    loading: {
      type: Boolean,
      required: true
    },
    callback: {
      type: Function,
      required: true
    },
    status: {
      type: [Number, String],
      require: true
    }
  },
  data() {
    return {
      dialog: false,
      downLoading: false
    }
  },
  watch: {
    list() {
      setTimeout(() => {
        this.$refs.table.doLayout()
      })
    }
  },
  methods: {
    see() {
      this.dialog = true
    },
    // 下载
    downLoad(id) {
      this.downLoading = true
      singleDownLoad(id)
        .then(res => {
          window.open(res.url)
          this.callback()
          this.downLoading = false
        })
        .catch(() => {
          this.downLoading = false
        })
    },
    toExamine() {},
    // 重新提交
    againSubmit({ id }) {
      this.$confirm('确认重新提交?', '提交操作？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          againApply(id).then(() => {
            this.callback(id)
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 打回平台重审
    rollback({ id }) {
      this.$confirm('确认打回平台重审?', '重审操作？', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          rollback(id).then(() => {})
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    // 查看详情
    seeDetail(id) {
      this.$router.push({
        path: '/menu/report-admin/silver-fill-detail',
        query: {
          id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
</style>